package com.itheima;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Jdbc_demo {
    public static void main(String[] args) throws Exception{
        //1.注册驱动
        Class.forName("com.mysql.jdbc.Driver");//可以获取此类的对象
        //2.获取连接
        Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/xuchao","root","root");
        //3.通过连接对象获取执行者对象
        Statement stat= con.createStatement();
        //4.执行sql语句,并返回结果
        String sql="SELECT * FROM emp";
        ResultSet rs = stat.executeQuery(sql);
        //5.处理结果
        while (rs.next()){
            System.out.println(rs.getInt("empno")+"\t"+rs.getString("ename"));
        }
        //6.释放资源
        con.close();
        stat.close();
        rs.close();
    }


}
